﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace CrossLine
{
    class TimerController
    {
        Timer t = new Timer();

        public TimerController() { }

        public TimerController(int interval)
        {
            t.Interval = interval;
        }

        public void MonitorInterval(int interval)
        {
            t.Interval = interval;
        }

        public void MonitorStart()
        {
            t.Elapsed += new ElapsedEventHandler(Monitor);//到达时间的时候执行事件；
            t.AutoReset = true;//设置是执行一次（false）还是一直执行(true)；
            t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件；
            t.Start();
            while (true) { }
        }

        private void Monitor(object source, System.Timers.ElapsedEventArgs e)
        {
            DateTime now = DateTime.Now;
            LogUtil.LogLine("开始时间：" + now.ToString());
            Stopwatch watch = new Stopwatch();
            watch.Start();

            Monitor m = new Monitor();
            m.monitor();

            watch.Stop();
            double time = watch.ElapsedMilliseconds;
            LogUtil.LogLine("分析用时：" + time + " 毫秒");
            LogUtil.LogLine("扫描完毕");
            LogUtil.LogLine("***********************************************");
        }
    }
}
